"""给你一个字符串 s，找到 s 中最长的回文子串。"""
class Solution:
    def rightleft(self,s,left,right):
        while left>=0 and right<len(s) and s[left]==s[right]:
            left-=1
            right+=1
        return left+1,right-1
    def longestPalindrome(self, s: str) -> str:
        length=0
        begin=0
        n=len(s)
        for i in range(n):
            left1,right1=self.rightleft(s,i,i)
            left2,right2=self.rightleft(s,i,i+1)
            if (right1-left1+1)>length:
                begin=left1
                length=right1-left1+1
            if (right2-left2+1)>length:
                begin=left2
                length=right2-left2+1
        return s[begin:begin+length]
